package io.summer.basis.dbg;

import io.summer.basis.core.MyApplicationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.boot.autoconfigure.jackson.JacksonProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author ml
 */
@Component
public class LogEnvironment extends MyApplicationContext {
  private final Logger log = LoggerFactory.getLogger(LogEnvironment.class.getSimpleName());

  @Override
  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    super.setApplicationContext(applicationContext);
    if (isDev()) {
      logEnv();
      logObjectMapper();
    }
  }

  private void logEnv() {
    log.debug("env: {}", applicationContext.getEnvironment());
  }

  private void logObjectMapper() {
    JacksonProperties properties = applicationContext.getBean(JacksonProperties.class);
    log.info("objectMapper: ");
    log.info("date format: {}", properties.getDateFormat());
    log.info("locale: {}", properties.getLocale());
    log.info("property include: {}", properties.getDefaultPropertyInclusion());
    log.info("property naming strategy: {}", properties.getPropertyNamingStrategy());
    log.info("mapper: {}", properties.getMapper());
  }
}
